--
-- Author: shunguo.chen
-- Date: 2018-03-19 15:05:10
--
-- ChessAction 星空谜棋事件

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	if data then
		self:init(data)
	end
end

-- data = 事件id
function ClassRef:init(data)
	self.id = data
	self._conf = GD:queryChessActionConf(self.id)

	self._icon = nil
	self._npcIn = nil
end

function ClassRef:isBattle()
	return self._conf.type == "11"
end

-- 是下回合生效的buff
function ClassRef:isBuff()
	return self._conf.type == "13"
end

function ClassRef:getName()
	return L(self._conf.name)
end

-- 获取需要显示的类型和参数，只在 前进／后退 有效
function ClassRef:getShowTypeValue()
	local tp = self._conf.type
	if tp == "2" or tp == "3" or tp == "13" then
		return tp, self._conf.value
	end
end

-- 获取需要显示的buff的类型和参数
function ClassRef:getShowBuffTypeValue()
	if self:isBuff() then
		local buffId = self._conf.value
		local conf = GD:queryChessBuffConf(buffId)
		return conf.type, conf.value
	end
end

function ClassRef:getMessage()
	return L(self._conf.message)
end

function ClassRef:getTarget()
	return L(self._conf.target)
end

-- 事件触发特效
function ClassRef:getCellFx()
	return self._conf.cellFx
end

-- 是否可逾越
function ClassRef:isPass()
	return self._conf.isPass == "1"
end

function ClassRef:getTipMsg()
	-- if not self._tipMsg then
	-- 	self._tipMsg = string.format("%s:%s", self:getName(), self:getMessage())
	-- end
	-- return self._tipMsg
	return self:getMessage()
end

function ClassRef:getDesc(isMe)
	return isMe and L(self._conf.descSelf) or L(self._conf.descOpp)
end

function ClassRef:getIcon()
	if not self._icon then
		self._icon = string.format(Res.chessIconPath, self._conf.icon)
	end
	return self._icon
end

function ClassRef:getIconSmall()
	if not self._iconSmall then
		self._iconSmall = string.format(Res.chessIconPath, self._conf.iconSmall)
	end
	return self._iconSmall
end

function ClassRef:getIconLight()
	if not self._iconLight then
		self._iconLight = string.format(Res.chessIconPath, self._conf.iconLight)
	end
	return self._iconLight
end

function ClassRef:getTipData(isMe)
	local ret = {}
	local msg = " [" .. self:getMessage() .. "]"
	local color = self:isBad() and "#ff510d" or "#83e500"
	local msg = display.getRichTextFontXml(msg, color)
	if isMe then
		ret.msg = string.format(L("lua_code_text_64"), msg)
	else
		local enemy = display.getRichTextFontXml(L("lua_code_text_504"), "#ff5151")
		ret.msg = string.format(L("lua_code_text_243"), enemy, msg)
	end
	ret.icon = self:getIconSmall()
	return ret
end

function ClassRef:isBad()
	return self._conf.isBad == "1"
end

-- 获取重复类型 0不限次数 1自己一次 2全体一次
function ClassRef:getRepeat()
	return self._conf["repeat"]
end

-- 需要npc show time
function ClassRef:npcShowTime()
	if not self._npcIn then
		self._npcIn = tonumber(self._conf.npcIn)
	end
	return self._npcIn
end

return ClassRef